<?php

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/* ADVANCED */

define('SET_SESSION_NAME','');			// Session name
define('DO_NOT_START_SESSION','1');		// Set to 1 if you have already started the session
define('DO_NOT_DESTROY_SESSION','1');	// Set to 1 if you do not want to destroy session on logout
define('SWITCH_ENABLED','1');		
define('INCLUDE_JQUERY','1');	
define('FORCE_MAGIC_QUOTES','0');
define('ADD_LAST_ACTIVITY','1');

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/* DATABASE */

include_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '/application/libraries/OFC/JSON.php';

if( !defined('_ENGINE_R_MAIN') ) {
  define('_ENGINE_R_CONF', true);
  define('_ENGINE_R_INIT', true);
  include_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'index.php';
}

// Create application, bootstrap, and run
$application = new Engine_Application(
  APPLICATION_ENV,
  array(
    'bootstrap' => array(
      'path' => APPLICATION_PATH . '/application/modules/' . APPLICATION_NAME . '/Bootstrap.php',
      'class' => ucfirst(APPLICATION_NAME) . '_Bootstrap',
    ),
    'autoloadernamespaces' => array(
      'Engine_',
    )
  )
);

Engine_Api::getInstance()->setApplication($application);
$application->getBootstrap()->bootstrap('frontcontroller');
$application->getBootstrap()->bootstrap('cache');
$application->getBootstrap()->bootstrap('db');
$application->getBootstrap()->bootstrap('frontcontrollermodules');
$application->getBootstrap()->bootstrap('session');
$application->getBootstrap()->bootstrap('manifest');
$application->getBootstrap()->bootstrap('router');
$application->getBootstrap()->bootstrap('view');
$application->getBootstrap()->bootstrap('modules');

$db = include dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR."application/settings/database.php";

// DO NOT EDIT DATABASE VALUES BELOW
// DO NOT EDIT DATABASE VALUES BELOW
// DO NOT EDIT DATABASE VALUES BELOW

define('DB_SERVER',					$db['params']['host']);
define('DB_PORT',					'3306');
define('DB_USERNAME',				$db['params']['username']);
define('DB_PASSWORD',				$db['params']['password']);
define('DB_NAME',					$db['params']['dbname']);
define('TABLE_PREFIX',				$db['tablePrefix']);
define('DB_USERTABLE',				'users');
define('DB_USERTABLE_NAME',			'displayname');
define('DB_USERTABLE_USERID',		'user_id');
define('DB_USERTABLE_LASTACTIVITY',	'lastactivity');

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/* FUNCTIONS */

function getUserID() {
	$userid = 0;
	
	$userid = Engine_Api::_()->user()->getViewer()->getIdentity();

	return $userid;
}


function getFriendsList($userid,$time) {
	$sql = ("select ".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_USERID." userid, ".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_NAME." username, ".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_LASTACTIVITY." lastactivity, CONCAT(".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_USERID." ,CONCAT('/',".TABLE_PREFIX.DB_USERTABLE.".photo_id)) avatar, ".TABLE_PREFIX.DB_USERTABLE.".username link, cometchat_status.message, cometchat_status.status from   ".TABLE_PREFIX."user_membership join ".TABLE_PREFIX."users  on ".TABLE_PREFIX."user_membership.user_id = ".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_USERID." left join cometchat_status on ".TABLE_PREFIX.DB_USERTABLE.".user_id = cometchat_status.userid where ".TABLE_PREFIX."user_membership.resource_id = '".mysql_real_escape_string($userid)."' and active = 1 order by username asc");

	if (defined('DISPLAY_ALL_USERS') && DISPLAY_ALL_USERS == 1) {
		$sql = ("select ".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_USERID." userid, ".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_NAME." username, ".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_LASTACTIVITY." lastactivity, CONCAT(".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_USERID." ,CONCAT('/',".TABLE_PREFIX.DB_USERTABLE.".photo_id)) avatar, ".TABLE_PREFIX.DB_USERTABLE.".username link, cometchat_status.message, cometchat_status.status from   ".TABLE_PREFIX."users   left join cometchat_status on ".TABLE_PREFIX.DB_USERTABLE.".user_id = cometchat_status.userid where ".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_USERID." <> '".mysql_real_escape_string($userid)."' and ('".$time."'-".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_LASTACTIVITY." < '".((ONLINE_TIMEOUT)*2)."') order by username asc");

	}

	return $sql;
}

function getUserDetails($userid) {
	$sql = ("select ".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_USERID." userid, ".TABLE_PREFIX."users.".DB_USERTABLE_NAME." username, ".TABLE_PREFIX."users.".DB_USERTABLE_LASTACTIVITY." lastactivity,  ".TABLE_PREFIX.DB_USERTABLE.".username link,  CONCAT(".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_USERID." ,CONCAT('/',".TABLE_PREFIX.DB_USERTABLE.".photo_id)) avatar, cometchat_status.message, cometchat_status.status from ".TABLE_PREFIX."users left join cometchat_status on ".TABLE_PREFIX."users.user_id = cometchat_status.userid where ".TABLE_PREFIX."users.user_id = '".mysql_real_escape_string($userid)."'");
	return $sql;
}

function updateLastActivity($userid) {
	$sql = ("update `".TABLE_PREFIX.DB_USERTABLE."` set ".DB_USERTABLE_LASTACTIVITY." = '".getTimeStamp()."' where ".DB_USERTABLE_USERID." = '".mysql_real_escape_string($userid)."'");
	return $sql;
}

function getUserStatus($userid) {
	 $sql = ("select ".TABLE_PREFIX."users.status message, cometchat_status.status from ".TABLE_PREFIX."users left join cometchat_status on ".TABLE_PREFIX."users.user_id = cometchat_status.userid where ".TABLE_PREFIX."users.user_id = '".mysql_real_escape_string($userid)."'");
	 return $sql;
}

function getLink($link) {
	return BASE_URL."../profile/".$link;
}

function getAvatar($image) {

	$results = explode('/',$image);

	$number = (((int)($results[0]/1000))*1000)+1000;

	if (is_file(dirname(dirname(__FILE__))."/public/viewer/1000000/".$number."/".$image.".jpg")) {
		return BASE_URL."../public/viewer/1000000/".$number."/".$image.".jpg";
	} 	else if (is_file(dirname(dirname(__FILE__))."/public/viewer/1000000/".$number."/".$image.".png")) {
		return BASE_URL."../public/viewer/1000000/".$number."/".$image.".png";
	}	else if (is_file(dirname(dirname(__FILE__))."/public/viewer/1000000/".$number."/".$image.".gif")) {
		return BASE_URL."../public/viewer/1000000/".$number."/".$image.".gif";
	} else if (is_file(dirname(dirname(__FILE__))."/public/user/1000000/".$number."/".$image.".jpg")) {
		return BASE_URL."../public/user/1000000/".$number."/".$image.".jpg";
	} 	else if (is_file(dirname(dirname(__FILE__))."/public/user/1000000/".$number."/".$image.".png")) {
		return BASE_URL."../public/user/1000000/".$number."/".$image.".png";
	}	else if (is_file(dirname(dirname(__FILE__))."/public/user/1000000/".$number."/".$image.".gif")) {
		return BASE_URL."../public/user/1000000/".$number."/".$image.".gif";
	} else {
		return BASE_URL."../application/modules/User/externals/images/nophoto_user_thumb_icon.png";
	}

}


function getTimeStamp() {
	return time();
}

function processTime($time) {
	return $time;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/* HOOKS */

function hooks_statusupdate($userid,$statusmessage) {
	$sql = ("update ".TABLE_PREFIX."users set status = '".mysql_real_escape_string($statusmessage)."', status_date = '".getTimeStamp()."' where user_id = '".mysql_real_escape_string($userid)."'");
 	$query = mysql_query($sql);
}

function hooks_forcefriends() {
	
}

function hooks_activityupdate($userid,$status) {

}

function hooks_message($userid,$unsanitizedmessage) {
	
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/* LICENSE */

// Fuck You Nadri, XripX and all other leechers who will steal my Cometchat and post it on your gay forum without giving credit to the original poster
// Remember! SEF is the no1 forum and nobody can beat us
// Long life to SEF

$p_ = 4;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


